package com.sb.registration.component.model.mapper.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.sb.registration.component.model.UserWrapper;
import com.sb.registration.component.model.mapper.UserDataMapper;
import com.sb.registration.data.jaxb.gen.Users.User;

@Component
public class UserDataMapperImpl implements UserDataMapper {
	
	private static Log logger_ = LogFactory.getLog(UserDataMapperImpl.class);

	public User getXMLUserObj(UserWrapper userData ) {
		
		User user = new User();
		user.setUsername(userData.getUsername());
		user.setEmail(userData.getEmail());
		user.setPostcode(userData.getPostcode());
		user.setChannel(userData.getChannel());
		user.setIpaddress(userData.getIpaddress());
		
		return user;
	}
	
	public UserWrapper getUserData(User user) {
		
		UserWrapper userVO = new UserWrapper();
		userVO.setUsername(user.getUsername());
		userVO.setEmail(user.getEmail());
		userVO.setPostcode(user.getPostcode());
		userVO.setChannel(user.getChannel());
		userVO.setIpaddress(user.getIpaddress());
		
		return userVO;
	}
	
	public List<UserWrapper> mapUserList(List<User> userList){
		List<UserWrapper> userWrapperList = new ArrayList<UserWrapper>();
		for(User user: userList){
			UserWrapper userWrapper = getUserData(user);
			userWrapperList.add(userWrapper);
		}
		return userWrapperList;
	}
}
